1. Field of the Invention
The present invention relates to a system and related method for accessing data, and more particularly, to a system and related method for accessing discrete data while utilizing fewer CPU resources and increasing the speed of accessing memory.
2. Description of the Prior Art
The demand for memory for storing audio and video data increases with the maturity and the prevalence of digital audio and video facilities. Among all categories, flash memory is one of the most popular memory types. Flash memory is a kind of non-volatile random access memory (NVRAM), and the data stored within can be changed rapidly. During its lifetime, a flash memory is capable of changing the data stored inside several thousands of times to several hundreds of thousands times. In addition, the price of flash memory is cheap; so many products are equipped with it. Furthermore, flash memory is capable of deleting several million bytes of data at a time. Compared with other popular non-volatile random access memories that can delete only one byte of data at a time, such as electrically erasable programmable read-only memory (EEPROM), flash memory is undoubtedly a better memory device. Among the numerous kinds of memory devices, the Secure Digital Memory Card (SD card) wins its market by its small size, which is preferred by consumers, and the copy protection mechanism of AV facilities. The SD card is a memory device developed by Panasonic, Toshiba, and Sundisk. Compared with conventional memory devices, the encryption/decryption algorithm of the Content Protection for Recordable Media (CPRM) is adopted for avoiding illegal copy and transmitting. The SD card is wildly applied in audio players, such as MPEG Layer3 (MP3) players.
The audio file is discrete data composed of a plurality of frames. When a player accesses data stored in a SD card, it needs to encrypt and decrypt the data frame by frame, which wastes a lot of resources of the central process unit (CPU) and wastes processing time. Please refer to FIG. 1. FIG. 1 is a diagram of an MPEG3 file 100. Reference number 102 is the file header of the file 100. Reference numbers 110 and 120 are the first two frames of the file 100, and there are more frames contained in the file 100. Every frame in the file 100 is similar to the frame 110 and the frame 120, including a frame header, a data block and a residual block. Reference numbers 112 and 122 are the frame headers of the frame 110 and the frame 120 respectively, and reference numbers 116 and 126 are the residual blocks of data parts of the frame 110 and the frame 120 respectively, wherein the remainder of the difference between the number of bytes of a frame and the number of bytes of the frame header divided by 8 is a first number, and the residual block is the set of the last first number bytes of the frame. For example, assume there are 432 bytes contained in the frame 110, and there are 4 bytes contained in the frame header 223. The remainder of (432−4)/8 is 4. So the residual block 116 will be the last 4 bytes of the frame 110, and there are 432−4−4=424 bytes contained in the data block 114. When encrypting the file 100 according to the CPRM algorithm and writing the encrypted file 100 into the SD card, the data blocks of all frames are written into the SD card after encryption, and the file header 102, all frame headers and all residual blocks are written into the SD card without encryption. Accordingly, when reading the file 100 encrypted according to CPRM algorithm from the SD card, the data block of all frames are written into the buffer after decryption, and the file header 102, all frame headers and all residual blocks are written into the buffer card without decryption.
When writing the file 100 into a SD card with conventional audio players, for example, when recording an audio file with a digital recorder, due to the aforementioned characteristic of the voice file, a digital signal processor (DSP) transforms the audio file into digital signals with a predetermined format and writes the file header 102 and the frames following the file header 102 into a buffer. Meanwhile, a CPU processes the data contained in the file 100 in turn. First of all, the CPU sends a write command of the file header 102 to the SD card, and writes the file header 102 into the SD card directly without encryption. When the writing is finished, the SD card will send a response signal. If the response signal is a writing succeeded signal, the CPU will send a write command of the frame header 112 of the frame 110 to the SD card, and write the frame header 112 into the SD card directly without encryption. When the writing is finished, the SD card will send a response signal. If the response signal is a writing succeeded signal, the CPU sends a write command of the data block 114 of the frame 110 to the SD card, sends the data block 114 into an encryption circuit, and then writes the encrypted data block 114 into the SD card. Similarly, when the writing is finished, the SD card will send a response signal. If the response signal is a writing succeeded signal, the CPU then sends a write command of the residual block 116 of the frame 110 to the SD card, and writes the residual block 116 into the SD card directly without encryption. Again, when the writing is finished, the SD card will send a response signal. If the response signal is a writing succeeded signal, the CPU processes the data of the frame 120 and other following frames according to the aforementioned procedure until all the frames contained in the file 100 have been written into the SD card.
Likewise, when a conventional audio player reads a file 100 from the SD card, for example, when an MP3 player plays an audio file recorded in the SD card, the CPU processes each data contained in the file 100 individually. First, the CPU sends a read command of the file header 102 to the SD card, and writes the file header 102 into the buffer directly without decryption. When the writing is finished, the SD card will send a response signal. If the response signal is a reading succeeded signal, the CPU then sends a read command of the frame header 112 of the frame 110 to the SD card, and writes the frame header 112 into the buffer directly without encryption. When the writing is finished, the SD card will send a response signal. If the response signal is a reading succeeded signal, the CPU sends a read command of the data block 114 of the frame 110 to the SD card, sends the data block 114 into an decryption circuit, and then writes the decrypted data block 114 into the buffer. Similarly, when the writing is finished, the SD card will send a response signal. If the response signal is a reading succeeded signal, the CPU then sends a read command of the residual block 116 of the frame 110 to the SD card, and writes the residual block 116 into the buffer directly without decryption. Again, when the writing is finished, the SD card will send a response signal. If the response signal is a reading succeeded signal, the CPU processes the data of the frame 120 and other following frames according to the aforementioned procedure until all the frames contained in the file 100 have been read from the SD card and written into the buffer. The DSP will process the data in the buffer simultaneously with the aforementioned procedure of the CPU, or the DSP will process the data after a predetermined amount of data have been written into the buffer.
It is easy to observe that in the prior art, for both reading a file from the SD card and writing a file into the SD card, the audio player needs to send a read command or a write command for each data contained in the file, read or write the data, and receive the response signal from the SD card. That is, the CPU needs to issue three commands for each data. Therefore, for each frame comprising a frame header, a data block and a residual block, and a file comprising N frames, the CPU has to issue 3×3×N commands totally both when writing the file and when reading the file, and the CPU has to write for 3×N times, which consumes a great deal of CPU resources and processing time.